protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String pagenoString = request.getParameter("current_pageno");
int current_pageno = 1;
try {
current_pageno = Integer.parseInt(pagenoString);
} catch (Exception e) {
e.printStackTrace();
}
UserinfoDao userinfoDao = new UserinfoDaoImpl();
//获取用户信息数量
int userinfoRowsCount = userinfoDao.getUserinfoCount();
//最大页数能被信息总数整除则最大页数为数量除以每一页条数否则为商加一
int max_page = (userinfoRowsCount % PageBean.USERINFOLIST_PER_ROWS == 0)
? (userinfoRowsCount / PageBean.USERINFOLIST_PER_ROWS)
: (userinfoRowsCount / PageBean.USERINFOLIST_PER_ROWS + 1);
if (current_pageno < 1) {
current_pageno = 1;
}
if (current_pageno > max_page) {
current_pageno = max_page;
}
List<Userinfo> userinfoList = userinfoDao.fetchUserinfoList(current_pageno);
PageBean userinfo_pageBean = new PageBean();
userinfo_pageBean.setCurrent_pageno(current_pageno);
userinfo_pageBean.setMax_page(max_page);
request.setAttribute("userinfo_pageBean", userinfo_pageBean);
request.setAttribute("userinfoList", userinfoList);
request.getRequestDispatcher("userinfoList.jsp").forward(request, response);
}
<tr>
<td colspan="4"><a href="UserinfoListServlet?current_pageno=1">首页</a>
<a
href="UserinfoListServlet?current_pageno=<%=userinfo_pageBean.getCurrent_pageno() - 1%>">上一页</a>
<a
href="UserinfoListServlet?current_pageno=<%=userinfo_pageBean.getCurrent_pageno() + 1%>">下一页</a>
<a
href="UserinfoListServlet?current_pageno=<%=userinfo_pageBean.getMax_page()%>">尾页</a></td>
</tr>